package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;

public class TestAutoComplete extends Activity implements TextWatcher {
	AutoCompleteTextView autoCompleteTextView;
	TextView selection;
	private String itemList[] = {"second","first", "autocmplete"};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.autocomplete);
		selection = (TextView) findViewById(R.id.AutoCompleteTextView);		
		autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.AutoCompleteText);
		autoCompleteTextView.addTextChangedListener(this);
		
		ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, itemList);
		
		autoCompleteTextView.setAdapter(aa);		
	}

	public void afterTextChanged(Editable s) {

	}

	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {

	}

	public void onTextChanged(CharSequence s, int start, int before, int count) {
		Log.d("PROVA", "onTextChanged="+s);
		selection.setText(autoCompleteTextView.getText());
	}

}
